public class maxValue {
    public int _maxValue(int[][] grid) {
        int sum = 0;
        if (grid.length == 0)
            return sum;

        int[][] dp = new int[grid.length][grid[0].length];
        dp[0][0] = grid[0][0];
        sum = grid[0][0];
        // 一行
        for (int i = 1; i < grid.length; i++) {
            dp[i][0] = dp[i - 1][0] + grid[i][0];
            sum = Math.max(dp[i][0], sum);
        }
        for (int i = 1; i < grid[0].length; i++) {
            dp[0][i] = dp[0][i - 1] + grid[0][i];
            sum = Math.max(dp[0][i], sum);
        }
        for (int i = 1; i < grid.length; i++) {
            for (int j = 1; j < grid[0].length; j++) {
                dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]) + grid[i][j];
                sum = Math.max(dp[i][j], sum);
            }
        }
        return sum;

    }
}
